<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.min.js"></script>
    <title>Todo</title>
</head>
<style>
    li span{
        display: inline-block;
        vertical-align: middle;
        line-height: 32px;
        text-align: center;
        width: 20%;
    }
</style>
<body>
    <div id="root">
        <p>
            <h3>待办事项</h3>
            <input type="text" v-model.trim="title" placeholder="请输入待办标题">
        </p>
        <p>
            <h3>处理时间</h3>
            <input type="date" v-model="date" placeholder="请输入处理时间">
            <button @click="addNewTodo">提交</button>
        </p>
        <hr>
        <div>
            <ul>
                <li>
                    <span>待办事项</span>
                    <span>处理时间</span>
                    <span>状态</span>
                    <span>操作</span>
                </li>
                <li v-for="item in list">
                    <span>{{item.title}}</span>
                    <span>{{item.date}}</span>
                    <span>{{item.state}}</span>
                    <span>
                        <button v-if="item.state === 'wait'" @click="handleTodo(item)">handle</button>
                        <button v-else-if="item.state === 'done'" @click="activeTodo(item)">active</button>
                    </span>
                </li>
            </ul>
        </div>
    </div>
    <script>
        new Vue({
            el:'#root',
            data(){
                return{
                    id:Date.now(),
                    title:'',
                    date:'',
                    list:[]
                }
            },
            methods:{
                handleTodo(item){
                    this.list.map(it =>{
                        if(item.id == it.id){
                            it.state = 'done'
                        }
                        return it
                    })
                },
                activeTodo(item){
                    this.list.map(it =>{
                        if(item.id == it.id){
                            it.state = 'wait'
                        }
                        return it
                    })
                },
                addNewTodo(){
                    if(!this.title){
                        alert('请输入后再提交')
                        return
                    }
                    if(!this.date){
                        alert('请选择后再提交')
                    }
                    this.list.push({
                        id:Date.now(),
                        title:this.title,
                        date:this.date,
                        state:'wait'
                    })
                }
            }
        })
    </script>
</body>
</html>